home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18114 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  58 lines

  1. Path: janus.cqu.edu.au!usenet
  2. From: Mutchg@Topaz.Cqu.Edu.Au (G.D.Mutch)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: returning a pointer to a struct with a class function
  5. Date: 18 Apr 1996 23:26:17 GMT
  6. Organization: CQ University
  7. Message-ID: <4l6j2p$38c@janus.cqu.edu.au>
  8. References: <4l5r9c$25s@dunlop.cs.strath.ac.uk>
  9. NNTP-Posting-Host: 138.77.57.12
  10. X-Newsreader: WinVN 0.92.6+
  11.  
  12. In article <4l5r9c$25s@dunlop.cs.strath.ac.uk>, jmccross@cs.strath.ac.uk (Joe McCrossan) says:
  13. >
  14. >Does anyone know how to set up a function within a class to return a pointer to a
  15. >struct ie
  16. >
  17. >        struct tree_node *Rotate(char *, struct tree_node *);
  18. >
  19. >as I can't seem to get it to work.  
  20. >
  21. >Any help would be greatly appreciated - please e-mail me.
  22. >
  23. >Thanks,
  24. >
  25. >Joe
  26.  
  27. The function you have stated looks illogical ? 
  28. You want a "Class" but you use a "Struct" this is ok but you loose
  29. meaningful understanding in your code. 
  30.  
  31.  
  32. Try  :
  33.         class tree_node {
  34.         private :
  35.          int x,y          
  36.          tree_node *Return;
  37.          .
  38.          .
  39.          .     
  40.         public :
  41.          tree_node() {Return=0;}     // constructor
  42.          ~tree_nod() {delete Return[];}    // destructor
  43.         
  44.          tree_node Rotate(char * , tree_node *return_val ) 
  45.         {
  46.           Return = new tree_node;    // allocate the memory
  47.            Return = return_val;         // if you prefer
  48.         }
  49.  
  50.         };//{eoc}
  51.  
  52. Remember you pointer is lost with the final call to your routine or program.
  53.  
  54. Common error is to point a variable to a delete data type.
  55.  
  56. -Gm
  57.  
  58.